extends Control

@onready var start_label: Label = $Start

func _ready():
	$AnimationPlayer.play("start")
	
	if start_label:
		# 初始设置为透明
		start_label.modulate.a = 0.0
		
		# 创建闪烁动画
		var tween = create_tween()
		tween.set_loops()
		tween.tween_property(start_label, "modulate:a", 0.5, 0.8)
		tween.tween_property(start_label, "modulate:a", 0.0, 0.8)
		
		# 添加轻微缩放效果
		var scale_tween = create_tween()
		scale_tween.set_loops()
		scale_tween.tween_property(start_label, "scale", Vector2(1.02, 1.02), 1.6)
		scale_tween.tween_property(start_label, "scale", Vector2(1.0, 1.0), 1.6)

func _input(event):
	# 检测点击
	if (event is InputEventMouseButton and event.pressed) or \
	   (event is InputEventScreenTouch and event.pressed):
		_handle_click()

func _handle_click():
	# 禁用进一步输入
	set_process_input(false)
	
	# 视觉反馈
	if start_label:
		# 立即显示label
		var feedback = create_tween()
		feedback.tween_property(start_label, "modulate:a", 1.0, 0.1)
		feedback.parallel().tween_property(start_label, "scale", Vector2(1.1, 1.1), 0.1)
		
		# 等待反馈完成
		await feedback.finished
		
		# 恢复原大小
		var recover = create_tween()
		recover.tween_property(start_label, "scale", Vector2(1.0, 1.0), 0.1)
	
	# 等待一点时间
	await get_tree().create_timer(0.2).timeout
	
	# 开始转场
	Translate.animated_grid()
	await Translate.animation_comlpeted
	
	# 切换场景
	get_tree().change_scene_to_file("res://Room/start.tscn")
